package com.ruoyi.jinchuguanli.service.impl;

import com.ruoyi.cangku.domain.Shangpinguanli;
import com.ruoyi.cangku.mapper.ShangpinguanliMapper;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.jinchuguanli.domain.SaomaReturn;
import com.ruoyi.jinchuguanli.domain.Saomachuku;
import com.ruoyi.jinchuguanli.domain.Shangpin;
import com.ruoyi.jinchuguanli.mapper.SaomachukuMapper;
import com.ruoyi.jinchuguanli.service.ISaomachukuService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * saomachukuService业务层处理
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Service
public class SaomachukuServiceImpl implements ISaomachukuService {
    @Autowired
    private SaomachukuMapper saomachukuMapper;

    @Autowired
    private ShangpinguanliMapper shangpinguanliMapper;

    /**
     * 查询saomachuku
     *
     * @param id saomachuku主键
     * @return saomachuku
     */
    @Override
    public Saomachuku selectSaomachukuById (Integer id) {
        return saomachukuMapper.selectSaomachukuById(id);
    }

    /**
     * 查询saomachuku列表
     *
     * @param saomachuku saomachuku
     * @return saomachuku
     */
    @Override
    public List<Saomachuku> selectSaomachukuList (Saomachuku saomachuku) {
        return saomachukuMapper.selectSaomachukuList(saomachuku);
    }

    /**
     * 新增saomachuku
     *
     * @param saomachuku saomachuku
     * @return 结果
     */
    @Override
    public int insertSaomachuku (Saomachuku saomachuku) {
        return saomachukuMapper.insertSaomachuku(saomachuku);
    }

    /**
     * 修改saomachuku
     *
     * @param saomachuku saomachuku
     * @return 结果
     */
    @Override
    public int updateSaomachuku (Saomachuku saomachuku) {
        return saomachukuMapper.updateSaomachuku(saomachuku);
    }

    /**
     * 批量删除saomachuku
     *
     * @param ids 需要删除的saomachuku主键
     * @return 结果
     */
    @Override
    public int deleteSaomachukuByIds (String ids) {
        return saomachukuMapper.deleteSaomachukuByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除saomachuku信息
     *
     * @param id saomachuku主键
     * @return 结果
     */
    @Override
    public int deleteSaomachukuById (Integer id) {
        return saomachukuMapper.deleteSaomachukuById(id);
    }

    @Override
    public List<SaomaReturn> selectSaomaChuKu4DanGedanhao(String danhao,int id) {
        List<Saomachuku> saomachukuList = saomachukuMapper.selectSaomaChuKu4DanGedanhao(danhao,id);
        List<SaomaReturn> saomaReturnList = new ArrayList<>();
        for (Saomachuku s:saomachukuList
             ) {
            Shangpinguanli shangpin = shangpinguanliMapper.selectShangpinguanliByBianHao(s.getShangpinbianhao());
            SaomaReturn saomaReturn = new SaomaReturn();
            BeanUtils.copyProperties(shangpin,saomaReturn);
            BeanUtils.copyProperties(s,saomaReturn);
            saomaReturnList.add(saomaReturn);
        }
        return saomaReturnList;
    }
}
